home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindlink.net!news
- From: genew@mindlink.bc.ca (Gene Wirchenko)
- Newsgroups: comp.lang.c
- Subject: Re: What should be returned?
- Date: Fri, 19 Jan 1996 06:53:14 GMT
- Organization: MIND LINK! - British Columbia, Canada
- Message-ID: <4dnf7d$1sa@fountain.mindlink.net>
- References: <4dj8pv$cjd@eng_ser1.erg.cuhk.hk> <30fd5c1a.5495936@nntp.ix.netcom.com>
- NNTP-Posting-Host: line121.nwm.mindlink.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- miker3@ix.netcom.com (Mike Rubenstein) wrote:
-
- >phsung@cs.cuhk.hk (the CAReLess boy) wrote:
-
- >|>Hi, all,
- >|>
- >|> It's said that the function main must return an integer value
- >|>but I just don't know what value should be returned. Also, if I
- >quit
- >|>main by exit(), what's the use of the return value?
- >|>
- >|> Any help?
-
- 0, EXIT_SUCCESS, EXIT_FAILURE. I think I spelled the last two
- right. Score two points each when you find them in your manual.
-
- >If you always use exit() from main, you need not have a return
- >statement. For example, the following is legal:
-
- > #include <stdlib.h>
- > int main(void)
- > {
- > exit(0);
- > }
-
- >In fact, it's even legal to have neither a return or exit():
-
- > int main(void)
- > {
- > }
-
- >This will return an undefined value to the operating environment, but
- >does not result in undefined behavior and will not do damage. I
-
- Returning an undefined value doesn't result in undefined
- bahavior? You been smokin' sumthin' funny, boy?
- What happens if/when the return value is interrogated as in
- MS-DOS's ERRORLEVEL or <other OS>'s <appropriate feature>?
-
- >strongly recommend against this practice and many compilers will issue
- >a warning message.
-
- >What is not legal is to define main as returning a type other than
- >int. The above would be illegal if main were defined as void
- >main(void). Defining main as returing anything but int results in
- >undefined behavior; the standard allows the compiler to do anything
- >(format your disk, send email to your boss complaining about your
- >incompetence, ...).
-
- void main() almost has a defined result: it gets you flamed in
- comp.lang.c <G>.
-
- >Michael M Rubenstein
-
- Sincerely,
-
- Gene Wirchenko
-
- C Pronunciation Guide:
- y=x++; "wye equals ex plus plus semicolon"
- x=x++; "ex equals ex doublecross semicolon"
-
-